from telnetlib import DO

import numpy as np
from manim import *
from numpy import flip, insert
import math

LV, QL, QH, JH = '#75cfb8', '#bbdfc8', '#f0e5d8', '#ffc478'

class p1(MovingCameraScene):
    def construct(self):
        # self.camera.frame.save_state()
        # self.add(NumberPlane())
        # self.camera.frame.rotate(13*DEGREES,about_point=[0.0, 0.0, 1.0])
        t1=VGroup()
        for i in range(4):
            t1.add(Square(0.5).next_to(ORIGIN,UP,buff=i*0.5))
        t1.move_to([-3.3,0,0]).set_fill(RED,1)
        t2=self.tetris_2_3(1,0,1,1,1,0,JH).scale(0.5).next_to(t1)
        t3=self.tetris_2_3(1,1,1,1,0,0,YELLOW).scale(0.5).next_to(t2)
        t4=self.tetris_2_3(1,0,1,0,1,1,GREEN).scale(0.5).next_to(t3)
        t5=self.tetris_2_3(0,1,0,1,1,1,BLUE).scale(0.5).next_to(t4)
        t6=self.tetris_2_3(0,1,1,1,1,0,LV).scale(0.5).next_to(t5)
        t7=self.tetris_2_3(1,0,1,1,0,1,PURPLE).scale(0.5).next_to(t6)

        self.add(t1,t2,t3,t4,t5,t6,t7)
        self.wait()
    def tetris_2_3(self,a,b,c,d,e,f,color=WHITE):
        li=[]
        vg=VGroup()
        for i in range(1,-2,-1):
            for j in [-0.5,0.5]:
                li.append([j,i,0])
        li_square=[a,b,c,d,e,f]
        for i in range(len(li_square)):
            if li_square[i]==1:
                vg.add(Square(1).set_fill(color,1).move_to(li[i]))
        return vg

class p2(MovingCameraScene):
    def construct(self):
        # self.camera.frame.save_state()
        # self.add(NumberPlane())
        # self.camera.frame.rotate(13*DEGREES,about_point=[0.0, 0.0, 1.0])
        vg=VGroup()
        for i in range(4):
            for j in range(7):
                s = Square(0.5).shift(UP * i * 0.5 + RIGHT * j * 0.5)
                if (i+j)%2==0:
                    s.set_fill(GRAY,1)
                vg.add(s)
        vg1=VGroup()
        for i in range(4):
            for j in range(7):
                s = Square(0.5).shift(UP * i * 0.5 + RIGHT * j * 0.5)
                if (i+j)%2!=0:
                    s.set_fill(GRAY,1)
                vg1.add(s)
        self.add(vg.move_to(UP*1.1),vg1.move_to(DOWN*1.1))
        self.wait()

class p3(MovingCameraScene):
    def construct(self):
        # self.camera.frame.save_state()
        # self.add(NumberPlane())
        # self.camera.frame.rotate(13*DEGREES,about_point=[0.0, 0.0, 1.0])
        t1=VGroup()
        for i in range(4):
            s=Square(0.5).next_to(ORIGIN,UP,buff=i*0.5)
            if i%2==0:
                s.set_fill(GRAY,1)
            t1.add(s)
        t1.move_to([-3.3,0,0])
        t2=self.tetris_2_3(1,0,1,1,1,0,JH).scale(0.5).next_to(t1)
        t3=self.tetris_2_3(1,1,1,1,0,0,YELLOW).scale(0.5).next_to(t2)
        t4=self.tetris_2_3(1,0,1,0,1,1,GREEN).scale(0.5).next_to(t3)
        t5=self.tetris_2_3(0,1,0,1,1,1,BLUE).scale(0.5).next_to(t4)
        t6=self.tetris_2_3(0,1,1,1,1,0,LV).scale(0.5).next_to(t5)
        t7=self.tetris_2_3(1,0,1,1,0,1,PURPLE).scale(0.5).next_to(t6)

        self.add(t1,t2,t3,t4,t5,t6,t7)
        self.wait()
    def tetris_2_3(self,a,b,c,d,e,f,color=WHITE):
        li=[]
        vg=VGroup()
        for i in range(1,-2,-1):
            for j in [-0.5,0.5]:
                li.append([j,i,0])
        li_square=[a,b,c,d,e,f]
        for i in range(len(li_square)):
            if li_square[i]==1:
                s=Square(1).move_to(li[i])
                if (li[i][0]+li[i][1]+0.5)%2==0:
                    s.set_fill(GRAY, 1)
                vg.add(s)
        return vg

class p4(MovingCameraScene):
    def construct(self):
        # self.camera.frame.save_state()
        # self.add(NumberPlane())
        # self.camera.frame.rotate(13*DEGREES,about_point=[0.0, 0.0, 1.0])
        t1=VGroup()
        for i in range(4):
            s=Square(0.5).next_to(ORIGIN,UP,buff=i*0.5)
            if i%2!=0:
                s.set_fill(GRAY,1)
            t1.add(s)
        t1.move_to([-3.3,0,0])
        t2=self.tetris_2_3(1,0,1,1,1,0,JH).scale(0.5).next_to(t1)
        t3=self.tetris_2_3(1,1,1,1,0,0,YELLOW).scale(0.5).next_to(t2)
        t4=self.tetris_2_3(1,0,1,0,1,1,GREEN).scale(0.5).next_to(t3)
        t5=self.tetris_2_3(0,1,0,1,1,1,BLUE).scale(0.5).next_to(t4)
        t6=self.tetris_2_3(0,1,1,1,1,0,LV).scale(0.5).next_to(t5)
        t7=self.tetris_2_3(1,0,1,1,0,1,PURPLE).scale(0.5).next_to(t6)

        self.add(t1,t2,t3,t4,t5,t6,t7)
        self.wait()
    def tetris_2_3(self,a,b,c,d,e,f,color=WHITE):
        li=[]
        vg=VGroup()
        for i in range(1,-2,-1):
            for j in [-0.5,0.5]:
                li.append([j,i,0])
        li_square=[a,b,c,d,e,f]
        for i in range(len(li_square)):
            if li_square[i]==1:
                s=Square(1).move_to(li[i])
                if (li[i][0]+li[i][1]+0.5)%2!=0:
                    s.set_fill(GRAY, 1)
                vg.add(s)
        return vg